import java.util.LinkedList;

/**
 * Maintains a buffer of a phrase currently being read by the histogram app
 * @author gabriel
 *
 */
public class PhraseBuffer extends PhraseObject {

    /**
     * The length that a phrase should be
     */
    private int maxLength = 1;
    
    /**
     * Initializes a phrase buffer
     * @param bLength The length the phrase should be
     */
    public PhraseBuffer(int bLength) {
        maxLength = bLength;
        wordList = new LinkedList();
        lineNumbers = new LinkedList();
    }
    
    /**
     * Cleans the list of line numbers
     *
     */
    public void flushLineNumbers()
    {
    	lineNumbers=new LinkedList();
    }
    
    /**
     * Builds a phrase buffer for phrases of length 1
     *
     */
    public PhraseBuffer() {
        this(1);
    }

    /**
     * Adds a word to the end of the phrase. It will push out the first word
     * if we exceed maxLength
     * @param word The word to add
     */
    public void pushWord(String word) {
        ((LinkedList) wordList).addLast(word);
        if (wordList.size() > maxLength) {
            ((LinkedList) wordList).removeFirst();
        }
    }

    /**
     * Determines if a phrase is filled up yet to max length
     * @return true if the phrase is full
     */
    public boolean isFullPhrase() {
        return wordList.size() == maxLength;
    }
    
    /**
     * Get the length this phrase should be when full
     * @return Returns the maxLength.
     */
    public int getMaxLength() {
        return maxLength;
    }

}
